package com.service.impl;

import com.dao.SysUserDao;
import com.domain.PageObject;
import com.domain.sys.SysUserDept;
import com.service.SysUserService;
import com.util.MyValid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    private SysUserDao sysUserDao;

    @Override
    public PageObject<SysUserDept> findPageObjects(String username, Integer pageCurrent) {

        MyValid.isService(pageCurrent==null||pageCurrent<1,"当前页码值无效");

        Integer row = sysUserDao.getRowCount(username);

        MyValid.isService(row == 0,"没有找到对应记录");

        int pageSize = 10;
        int startIndex = (pageCurrent - 1) * pageSize;
        ArrayList<SysUserDept> records = sysUserDao.findPageObjects(username,startIndex,pageSize);

        int pageCount  = row / pageSize;
        if(row % pageSize != 0)
            pageCount += 1;
        return new PageObject<SysUserDept>(pageCurrent,pageSize,row,pageCount,records);
    }
}
